/**
 * author:Administrator
 * date:2016/1/6
 * desc:TODO
 */

'use strict';

var Model = require('../model/Coupon.js');
var sequelize = require('sequelize');

let CommonDao = require('./_commonDao.js');
class TheDao extends CommonDao {
  constructor() {
    super(Model);
  }

  * decrease(id, count) {
    let attr = {remain: sequelize.literal('remain-' + count)};
    let where = {id: id, remain: {gte: count}};
    let affRows = yield this.update(where, attr);
    //console.log('decrease coupon, affRows=', affRows);
    return !!affRows;
  }
}
module.exports = new TheDao();
